import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Timer;

public class Bunneh implements ActionListener, Followable, Collidable
{

	int x;
	int y;
	Timer t;
	boolean on;
	boolean[] run = new boolean[4];
	BufferedImage bun;
	Followable followed;

	public Bunneh(Followable foll, int sx, int sy){

		x = sx;
		y = sy;
		
		followed = foll;
		
		try{

			bun = ImageIO.read(new File("src/daREALZbunneh.png"));
			t = new Timer(10, this);
			t.start();
			
		}

		catch(IOException e) {

			System.out.println(e.getMessage());
		}
	}

	public Image getImage(){

		return bun;
	}


	public int getX(){
		return x;


	}

	public int getY(){
		return y;


	}

	
	public void paint(Graphics2D g2d)
	{
		g2d.drawImage(bun, x, y, null);
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		update(followed);
	}
	
	
	public void update(Followable b)
	{
		if(x >b.getX())
		{
			x = x-3;
		}
		
		if(x < b.getX())
		{
			x = x+3;
		}
		if(y < b.getY())
		{
			y = y+3;
		}
		if(y > b.getY())
		{
			y = y-3;
		}
	}

	@Override
public Rectangle2D.Double shape()
	{
		
		Rectangle2D.Double rect = new Rectangle2D.Double(x, y, bun.getWidth()-100, bun.getHeight()-100);
		return rect;
	}
	
	

}
